﻿<?php include("conn.php") ?>
<?php
$conn=new Mysql();
if($_GET["Type"]=="Del"){
	$conn->query("delete from menus where id=".$_GET["id"]);
	GoLink("system-menu.php");
	}else if($_POST["Type"]=="add"){
		
		$menuT=$_POST["menuT"];
		if($menuT!=""){
			if($conn->query("insert into menus(menuT,menuL,px,level,lev_id) value('".$_POST["menuT"]."','".$_POST["menuL"]."',".$_POST["px"].",1,0)")){
						GoLink("system-menu.php");
				}else{
					echo "error";
					}

			}
		}else if($_POST["Type"]=="Edit"){
			
			$sql="update menus set menuT='".$_POST["menuT"]."',menuL='".$_POST["menuL"]."',px=".$_POST["px"]." where id=".$_POST["id"];
				if($conn->query($sql)){
						GoLink("system-menu.php");
				}else{
					echo "error";
					}

		}else if($_POST["Type"]=="addlevel"){
		
		$menuT=$_POST["menuT"];
		if($menuT!=""){
			if($conn->query("insert into menus(menuT,menuL,px,level,lev_id) value('".$_POST["menuT"]."','".$_POST["menuL"]."',".$_POST["px"].",2,".$_POST["lev_id"].")")){
						GoLink("system-menu.php");
				}else{
					echo "error";
					}

			}
		}
?>
<!--_meta 作为公共模版分离出去-->
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
<?php include("public/cssjs.php");?>
<link href="lib/webuploader/0.1.5/webuploader.css" rel="stylesheet" type="text/css" />
<!--/meta 作为公共模版分离出去-->
<title>基本设置</title>
</head>
<body>
<nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页
	<span class="c-gray en">&gt;</span>
	系统管理
	<span class="c-gray en">&gt;</span>
	基本设置
	<a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" ><i class="Hui-iconfont">&#xe68f;</i></a>
</nav>

<div class="page-container">
	 <?php

	$sql = "select * from menus where level=1  order by px asc";
	$page_size = 20;					 //定义每页显示多少记录
     $num_cnt = mysqli_num_rows($conn->query($sql)); //获取总记录数
	$page_cnt = ceil($num_cnt/$page_size);  //计算总页数	
	if(isset($_GET["page"])){
		$page = intval($_GET["page"]);
	}else{
		$page = 1;
	}
    if ($page<1)
	{
        $page=1;
	}
    elseif ($page>$page_cnt)
	{
        $page=$page_cnt;
    }
	$query_start = ($page - 1 ) * $page_size;   //计算每页开始的记录号
	$query_sql = $sql." limit $query_start,$page_size"; //使用limit获取记录

?>
<table class="table table-striped table-hover table-bordered" id="editable-sample">
  <tr bgcolor="#799AE1" class="blueLine">
    <td width="25%">栏目标题</td>
    <td width="33%">跳转地址</td>
    <td width="13%">当前级别</td>
    <td width="13%">上级级别</td>
    <td>操作</td>
  </tr>
<?php
if($num_cnt>0)
{
    $row=$conn->getAll($query_sql);
    foreach($row as $key=>$rs){
?>
  <tr onMouseOver="this.style.backgroundColor='#F3F3F3'" onMouseOut="this.style.backgroundColor='#FFFFFF'">
	  <td align="center">&nbsp;<b><?= $rs["menuT"] ?></b></td>
	  <td height="22"><div align="center">&nbsp;<?php echo $rs["menuL"]; ?></div></td>
      <td  height="22"><div align="center">&nbsp;<?php echo $rs["level"]; ?></div></td>
      <td height="22"><div align="center">&nbsp;<?php echo $rs["lev_id"]; ?></div></td>
	  <td style="text-align:center">
      <a style="text-decoration:none" class="ml-5" href="system-menu.php?Type=Edit&id=<?php echo $rs["id"];?>" title="编辑"><i class="Hui-iconfont">&#xe6df;</i></a> <a style="text-decoration:none" class="ml-5" href="system-menu.php?Type=addlevel&id=<?php echo $rs["id"];?>" title="添加"><i class="Hui-iconfont">&#xe600;</i></a> <a style="text-decoration:none" class="ml-5" href="system-menu.php?Type=Del&id=<?php echo $rs["id"];?>" title="删除"><i class="Hui-iconfont">&#xe6e2;</i></a>
     </td>
	</tr>
<?php
	$conn2=new Mysql();
        $row=$conn2->getAll("select * from menus where lev_id=".$rs["id"]."  order by px asc");
	foreach($row as $k=>$rss2){
		?>
		 <tr onMouseOver="this.style.backgroundColor='#F3F3F3'" onMouseOut="this.style.backgroundColor='#FFFFFF'">
	  <td align="center">&nbsp;==><b><?php echo $rss2["menuT"]; ?></b></td>
	  <td height="22"><div align="center">&nbsp;<?php echo $rss2["menuL"]; ?></div></td>
      <td  height="22"><div align="center">&nbsp;<?php echo $rss2["level"];?></div></td>
      <td height="22"><div align="center">&nbsp;<?php echo $rss2["lev_id"]; ?></div></td>
	  <td style="text-align:center">
      <a style="text-decoration:none" class="ml-5" href="system-menu.php?Type=Edit&id=<?php echo $rss2["id"];?>" title="编辑"><i class="Hui-iconfont">&#xe6df;</i></a>  <a style="text-decoration:none" class="ml-5" href="system-menu.php?Type=Del&id=<?php echo $rss2["id"];?>" title="删除"><i class="Hui-iconfont">&#xe6e2;</i></a>
     </td>
	</tr>
		<?
		}
	}
}else{
?>
  <tr onMouseOver="this.style.backgroundColor='#F3F3F3'" onMouseOut="this.style.backgroundColor='#FFFFFF'">
    <td height="22" colspan="3" align="center" style="color:#FF0000;">暂无导航信息</td>
  </tr>  
<?
}
?>
 
</table>
                         
                     </section>
                     <section>
                     <form method="post" action="system-menu.php">
                     <?
					 $utype=$_GET["Type"];
					 if($utype==""){ $typere="add";}else{ $typere=$utype;}

                     if(isset($_GET["id"])){$pid=$_GET["id"];}else{$pid=46;}
                     $conn=new Mysql();
					 $rs=$conn->getRow("select * from menus where id=".$pid);
					 
					 ?>
                     <input type="hidden" name="Type" value="<?=$typere?>">
                     <table class="table table-bordered">
                     
  
  <?
  if($typere=="addlevel"){
	  ?>
	  <input type="hidden" name="level" value="2">
	   <tr >
    <td align="right" >上级导航：</td>
    <td ><input type="hidden" name="lev_id" value="<?php echo $rs["id"];?>"><input name="menuT_lev_id"  value="<?php echo $rs["menuT"];?>"  class="input-text"  type="text" size="100" /></td>
  </tr>
   <tr >
    <td align="right" >栏目标题：</td>
    <td ><input name="menuT"    class="input-text"  type="text" size="100" /></td>
  </tr>
  <tr >
    <td align="right" >跳转地址：</td>
    <td ><input name="menuL"    class="input-text" type="text" size="100" /></td>
  </tr>
  <tr >
    <td align="right" >排序编号：</td>
    <td ><input name="px"  type="text"   class="input-text"   size="100"  /></td>
  </tr>
	  <?
	  }else{
		   ?>
	  <input type="hidden" name="level" value="1"><input type="hidden" name="lev_id" value="0">
       <tr >
    <td align="right" >栏目标题：</td>
    <td ><input type="hidden" name="id" value="<?php echo $_GET["id"];?>"><input name="menuT"  value="<?php echo $rs["menuT"];?>"  class="input-text"  type="text" size="100" /></td>
  </tr>
  <tr >
    <td align="right" >跳转地址：</td>
    <td ><input name="menuL"  value="<?php echo $rs["menuL"];?>"   class="input-text" type="text" size="100" /></td>
  </tr>
  <tr >
    <td align="right" >排序编号：</td>
    <td ><input name="px"  type="text"  value="<?php echo $rs["px"];?>"  class="input-text"   size="100"  /></td>
  </tr>
	  <?
		  }
  ?>
 
  
  <tr>
    <td colspan="2" align="center" bgcolor="#FFFFFF"><input name="Submit" type="submit" class="btn btn-xs btn-danger" value="　保  存　">　　　</td>
    </tr>
 
 </table>
                     </form>
                     </section>
</div>

<!--_footer 作为公共模版分离出去-->
<script type="text/javascript" src="lib/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript" src="lib/layer/2.4/layer.js"></script>
<script type="text/javascript" src="static/h-ui/js/h-ui.min.js"></script>
<script type="text/javascript" src="static/h-ui.admin/js/h-ui.admin.js"></script> <!--/_footer 作为公共模版分离出去-->

<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="lib/My97DatePicker/4.8/WdatePicker.js"></script>
<script type="text/javascript" src="lib/jquery.validation/1.14.0/jquery.validate.js"></script>
<script type="text/javascript" src="lib/jquery.validation/1.14.0/validate-methods.js"></script>
<script type="text/javascript" src="lib/jquery.validation/1.14.0/messages_zh.js"></script>


<script type="text/javascript">
$(function(){
	$('.skin-minimal input').iCheck({
		checkboxClass: 'icheckbox-blue',
		radioClass: 'iradio-blue',
		increaseArea: '20%'
	});
	$("#tab-system").Huitab({
		index:0
	});
	$("#btn-star").click(function(){
		var files=$("#file-2").val();
		$.get("json/upload.php?files="+files,function(data){
			alert(data);
			})
		})
});
</script>
<!--/请在上方写此页面业务相关的脚本-->
</body>
</html>
